﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.ExportToPLMX.SimulationStateExporter.CApExportToPlmxSimulationFileExporter
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;
using System.Text;


namespace DnProcessSimulateCommands.ExportToPLMX.SimulationStateExporter;

[DataContract]
internal class CApExportToPlmxSimulationFileExporter
{
  [DataMember(Order = 0)]
  public string[] idArray;
  [DataMember(Order = 1)]
  public List<CApExportToPlmxObjectsFrameData> animOperations = new List<CApExportToPlmxObjectsFrameData>();
  [DataMember(Order = 2)]
  public List<CApExportToPlmxOperationsData> animSteps = new List<CApExportToPlmxOperationsData>();

  internal void SaveToFile(string filePath)
  {
    try
    {
      byte[] array;
      using (MemoryStream memoryStream = new MemoryStream())
      {
        new DataContractJsonSerializer(this.GetType()).WriteObject((Stream) memoryStream, (object) this);
        array = memoryStream.ToArray();
      }
      using (StreamWriter streamWriter = new StreamWriter(filePath, false))
        streamWriter.Write(Encoding.UTF8.GetString(array, 0, array.Length));
    }
    catch (Exception ex)
    {
      string message = ex.Message;
    }
  }

  public override bool Equals(object other)
  {
    CApExportToPlmxSimulationFileExporter simulationFileExporter = other as CApExportToPlmxSimulationFileExporter;
    List<string> list1 = ((IEnumerable<string>) this.idArray).ToList<string>();
    List<string> list2 = ((IEnumerable<string>) simulationFileExporter.idArray).ToList<string>();
    bool flag = this.Equals(list1, list2) && this.animSteps.Count.Equals(simulationFileExporter.animSteps.Count) && this.animOperations.Count.Equals(simulationFileExporter.animOperations.Count);
    for (int index = 0; index < this.animSteps.Count & flag; ++index)
      flag = this.animSteps[index].Equals((object) simulationFileExporter.animSteps[index]);
    for (int index = 0; index < this.animOperations.Count & flag; ++index)
      flag = this.animOperations[index].Equals((object) simulationFileExporter.animOperations[index], list1, list2);
    return flag;
  }

  private bool Equals(List<string> thisList, List<string> otherList)
  {
    bool flag = thisList.Count == otherList.Count;
    foreach (string str in thisList)
    {
      string item = str;
      flag = flag && otherList.Exists((Predicate<string>) (x => x == item));
    }
    return flag;
  }
}
